<?xml version="1.0" encoding="utf-8" ?>
[#include "/WEB-INF/pages/common/taglibs.ftl"]
[#macro _script]
	<link rel="stylesheet" href="[@c.url value='/js/plugins/jquery-ztree/css/zTreeStyle/zTreeStyle.css'/]" type="text/css">
	<script type="text/javascript" src="[@c.url value='/js/plugins/jquery.alerts.js'/]"></script>
	<script type="text/javascript" src="[@c.url value='/js/plugins/jquery-ztree/js/jquery.ztree.core-3.1.js'/]"></script>
	<script type="text/javascript">
		var base = (function(){
			// 事件绑定
			function _addEventListeners() {
				// 一览
				// 删除所选
				$('a.delete').click(function(){
					var tb = jQuery(this).attr('tableid');	
					var sel = false;											//initialize to false as no selected row
					var ch = jQuery('#'+tb).find('tbody input[type=checkbox]');	//get each checkbox in a table
					var content = "功能删除后将无法恢复,是否仍要删除?";
					var title = "删除所选功能";
					jConfirm(content, title, function(r) {
						if (r) {
							// 这里存在问题,form没有被提交
							var _$form = $('<form action="[@c.url value="/manage/Function_rm.action"/]" method="post"></form>');
							alert(_$form.html());
							var index = 0;
							ch.each(function(){
								if(jQuery(this).is(':checked')) {
									sel = true;	
									var id = $(this).val();
									$(this).parents('tr').fadeOut(function(){
										$(this).remove();							//remove row when animation is finished
									});
									_$form.append("<input type='hidden' name='functionList["+index+"].id' value="+id+" />");
									index ++;
								}
							});
							if (sel) {
								alert(_$form.html());
								_$form.submit();
							} else {
								jAlert('No data selected');
							}
						}
					});
				});
			}
			
			// 页面渲染
			function _treeRender () {
				var zNodes =[@s.action name="Function_tree" executeResult="true" namespace="/manage"]
			    		[@s.param name="ajax" value="true" /]
			    	[/@s.action];
	            var setting = {
						data: {
							simpleData: {
								enable: true
							}
						},
						view: {
							// 渲染树
							addDiyDom: function (treeId, treeNode) {
								// 根节点以外的父节点
								//if (treeNode.tId != treeId + "_1" && treeNode.isParent) {
								//	$('#' + treeNode.tId).append("<a href='javascript:void(0);' onClick=\"return base.rmDir('" + treeNode.id + "')\">[删除]</a>");
								//}
								//if (treeNode.pId != null) {
								//	$('#' + treeNode.tId).append("<a href='javascript:void(0);' onClick=\"return base.rmDir('" + treeNode.id + "')\">[删除]</a>");
								//}
							}
						},
						callback: {
							onClick: function(event, treeId, treeNode, clickFlag){
								var isParent = treeNode.isParent;
								var id = treeNode.id;
								$.get(base.config.url, {'id':id, 'ajax':true, 'piece':true}, function(data){
				                	$('#categoryTableList').html(data);
				                	_addEventListeners();
				                });
							}
						}
					};
				$.fn.zTree.init($("#functionTree"), setting, zNodes);
			}
			return {
                config: {
                	url : null,
                    theme: null
                },
                init: function () {
                	_addEventListeners();
                	_treeRender();
                }
			}
		}());
		
		$(function(){
			var link = "[@c.url value='/manage/Function_list.action?currentPage=${currentPage}'/]";
			base.config.theme = getTheme();
			base.config.url = link;
            //Initializing the form
			base.init();
		})
	</script>
[/#macro]
[#if piece==true]
	[@_script /]
	<!--设置提交行为-->
	[#assign act="save" /]
	<!--设置table渲染到指定ID节点-->
	[#assign renderTo="#functionList"]
	[#include "/WEB-INF/pages/manage/Function/_functionList.ftl"]
[#else]
	<html xmlns="http://www.w3.org/1999/xhtml">
	<head>
		<title>Insert title here</title>
		<meta name="menu" content="AdminMenu"/>
		<meta name="heading" content="heading"/>
		<style type="text/css">
			.article {
				padding:0;
				margain:0;
			}
			.function_tree {
				width:240px;
				/*height:500px;*/
				float:left;
				margin-left:2px;
			}
			.function_list {
				/*height:500px;*/
				margin-left:248px;
			}
		</style>
		[@_script /]
	</head>
	<body id="body" class="art_content">
		<div class="contenttitle radiusbottom0" style="margin-bottom:1px;">
	    	<h2 id="vertical" class="form"><span>功能维护</span></h2>
	    </div><!--contenttitle-->
    	<div class="wizard verwizard2" >
        	<div class="verticalmenu widgetbox anchor" style="width:220px;">
        		<!--tree--> 
        		<div class="widgetcontent announcement" style="height:500px;width:210px;overflow:auto;">
        			<ul id="functionTree" class="ztree"></ul>
        		 </div>
		    </div>
		</div>
		<div>
			<!--设置提交行为-->
			[#assign act="save" /]
			<!--设置table渲染到指定ID节点-->
			[#assign renderTo="#functionList"]
			<div id="functionList" class="function_list">
				[#include "/WEB-INF/pages/manage/Function/_functionList.ftl"]
			</div>
			<div style="clear: both;"></div>
		</div>
	</body>
	</html>
[/#if]